package com.aic.aicdetactor.service;

import com.aic.aicdetactor.broadcast.EvalBroadcastReceiver;
import com.aic.aicdetactor.broadcast.Keys;
import com.aic.aicdetactor.broadcast.Peak2PeakReceiver;
import com.aic.aicdetactor.broadcast.PeakValReceiver;
import com.aic.aicdetactor.broadcast.RpmReceiver;
import com.aic.aicdetactor.broadcast.TempBroadcastReceiver;

import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;

public class BroadcastService extends Service {

	private TempBroadcastReceiver tempReceiver;
	
	private EvalBroadcastReceiver evalReceiver;
	
	private PeakValReceiver peakValReceiver;
	
	private Peak2PeakReceiver peak2PeakReceiver;
	
	private RpmReceiver rpmReceiver;
	
	private String TEMP_ACTION = Keys.TEMP_ACTION;
	
	private String EVALUE_ACTION = Keys.EVALUE_ACTION;
	
	private String VIBPEAK_ACTION = Keys.VIBPEAK_ACTION;
	
	private String VIB_PEAK2PEAK_ACTION = Keys.VIB_PEAK2PEAK_ACTION;
	
	private String RPM_ACTION = Keys.RPM_ACTION;
	
	

	public BroadcastService() {
	}
	
	@Override
	public IBinder onBind(Intent intent) {
		throw new UnsupportedOperationException("Not yet implemented");
	}
	
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		tempReceiver = new TempBroadcastReceiver();
		evalReceiver = new EvalBroadcastReceiver();
		peakValReceiver = new PeakValReceiver();
		peak2PeakReceiver = new Peak2PeakReceiver();
		rpmReceiver = new RpmReceiver();
		registerReceiver(tempReceiver, new IntentFilter(TEMP_ACTION));
		registerReceiver(evalReceiver, new IntentFilter(EVALUE_ACTION));
		registerReceiver(peakValReceiver, new IntentFilter(VIBPEAK_ACTION));
		registerReceiver(peak2PeakReceiver, new IntentFilter(VIB_PEAK2PEAK_ACTION));
		registerReceiver(rpmReceiver, new IntentFilter(RPM_ACTION));
	
		return super.onStartCommand(intent, flags, startId);
	}
	
	@Override
	public void onDestroy() {
		unregisterReceiver(tempReceiver);
		unregisterReceiver(evalReceiver);
		unregisterReceiver(peakValReceiver);
		unregisterReceiver(peak2PeakReceiver);
		unregisterReceiver(rpmReceiver);
		super.onDestroy();
	}
	
	
	
	
}
